package org.java.desgin.patterns.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;

public class DynamicProxyTest {
	public static void main(String[] args) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
		Object proxyObj = Proxy.newProxyInstance(
				LenovoNotebook.class.getClassLoader(),
				LenovoNotebook.class.getInterfaces(),
				new ProxyInvocationHandler(new LenovoNotebook()));
		Computer cmp = (Computer) proxyObj;
		cmp.start();
		Class<?> proxyClzz = Proxy.getProxyClass(
				LenovoNotebook.class.getClassLoader(),
				LenovoNotebook.class.getInterfaces());

		Object proxyObj2 = proxyClzz.getConstructor(
				new Class[] { InvocationHandler.class }).newInstance(
				new ProxyInvocationHandler(new LenovoNotebook()));
		
		Notebook nb=(Notebook)proxyObj2;
		nb.notebook();

	}
}
